﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.SS.Formula.Functions;
using WMSUIMVC.DTO.OutBount;
using WMSUIMVC.DTO.Product;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class OutBoundController : Controller
    {

        private readonly IConfiguration _configuration;

        public OutBoundController(IConfiguration configuration)
        {
            _configuration = configuration;
        }


        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获取出库列表
        /// </summary>
        /// <returns></returns>
        public IActionResult GetOutBoundList()
        {
            return View();
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public IActionResult AddOutBound()
        {
            return View();
        }


        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public IActionResult EditOutBound()
        {
            return View();
        }

        /// <summary>
        /// 添加出库
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AddOutShip(AddOutShip data)
        {
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckx/api/OutBound/AddOutShip" ;
            var resdata = JsonConvert.SerializeObject(data);
            var response = await client.PostAsync(url, resdata);
            return Json(response);
        }




        /// <summary>
        /// 获取出库列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetOutShipList(SelectShowDTO data)
        {
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckd/api/OutBound/GetOutSHipList?pageIndex=" + data.pageIndex + "&pageSize=" + data.pageSize + "&OutCode=" + data.OutCode;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        
        /// <summary>
        /// 获取出库明细
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<IActionResult> OutShipDetail(OutShipDetail data)
        {
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckd/api/OutBound/GetOutShipDetail?OutShipId="+data.OutShipId;
            var response = await client.GetAsync(url);
            return Json(response);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<IActionResult> OutShipDel(OutShipDelDTO data)
        {
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckx/api/OutBound/DelOutShip";
            var resdata = JsonConvert.SerializeObject(data);
            var response = await client.PutAsync(url, resdata);
            return Json(response);
        }

        /// <summary>
        /// 更新出库单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<IActionResult> OutShipUPT(AddOutShip data)
        {
            HttpClientWrapper client = new HttpClientWrapper(data.Token);
            string url = _configuration["Url"] + "ckx/api/OutBound/UptOutShip";
            var resdata = JsonConvert.SerializeObject(data);
            var response = await client.PutAsync(url, resdata);
            return Json(response);
        }


    }
}
